<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .demo {
      height: 10px;
      width: 0;
      background-color: aqua;
      border: 1px solid red;
      margin: 40px auto;
    }
  </style>
</head>
<body>
    <div class="demo"></div>
    <button>开始进度条</button>
    <script>
      // 实现一个进度条
      const div = document.querySelector('.demo')
      const btn = document.querySelector('button');
      let start;
      btn.addEventListener('click', () => {
        start = Date.now();
        window.requestAnimationFrame(progress)
      });

      function progress() {
        if (div.offsetWidth <= 100) {
          const current = Date.now();
          console.log('执行任务时间间隔：' + (current - start));
          start = current;
          div.style.width = div.offsetWidth + 1 + 'px';
          window.requestAnimationFrame(progress);
        }
      }
    </script>
</body>
</html>